<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/2/21 0021
 * Time: 8:40
 */
namespace app\admin\controller;
class Tag extends Common
{
  private $db;
  public function __construct()
  {
      $this->db=new \system\model\Tag();
  }
    public function index(){
      //获取数据
      $data=Db::table('tag')->get();
      //分配变量
      View::with('data',$data);
      return view();
  }

    /**添加标签
     * @return mixed
     */
  public function  addTag(){
      if(IS_POST){
         $res=$this->db->store();
         if($res){
             message('标签添加成功',u('index'),'success');
         }
          message('标签不能为空','back','error');
      }
      return view();
  }

    /**
     * 编辑标签
     */
  public  function editTag(){
      if(IS_POST){
          $tid=q('tid');
          $res=$this->db->editTag($tid);
          if($res){
              message('标签修改成功',u('index'),'success');
          }
          message('标签修改为空','back','error');
      }
      $tid=q('tid');
      $oldData=Db::table('tag')->find($tid);
      View::with('oldData',$oldData);
     return view();
  }
  public  function del(){
       $tid=q('get.tid');
       $res=Db::table('tag')->where('tid',$tid)->delete();
       if($res){
           message('删除成功','index','success');
       }
      message('删除失败','back','error');
  }
}